enum CacheKey {
  LOCAL,
  SESSION,
}
class Cache {
  storage: Storage;
  constructor(type: CacheKey) {
    this.storage = type === CacheKey.LOCAL ? localStorage : sessionStorage
  };
  setCache(key: string, value: any) {
    if (value) {
      this.storage.setItem(key, JSON.stringify(value))
    }
  }
  getCache(key: string) {
    const value = this.storage.getItem(key)
    if (value) {
      return JSON.parse(value)
    }
  }
  removeCache(key: string) {
    this.storage.removeItem(key)
  }
  clearCache() {
    this.storage.clear()
  }
}

const localCache = new Cache(CacheKey.LOCAL);
const sessionCache = new Cache(CacheKey.SESSION);
export {
  localCache,
  sessionCache
}
